_require local "../../../../smlnj-lib/Util/binary-set-fn.smi"
_require local "../../../libs/env/main/IEnv.smi"
_require local "../../../libs/env/main/SEnv.smi"
_require local "../../../data/control/main/Control.smi"
_require local "COUNTER.sig"

_require "../../../../basis.smi"

structure Counter =
struct
  datatype counterSetOrder = ORDER_BY_NAME | ORDER_OF_ADDITION | ORDER_BY_TIME
  type accumulationCounter =
      {name: string,
      toString : counterSetOrder -> string -> string,
       inc: unit -> unit,
       dec: unit -> unit,
       add: int -> unit,
       sub: int -> unit,
       reset: unit -> unit,
       getValue: unit -> int}
  type minMaxCounter =
      {name: string,
      toString : counterSetOrder -> string -> string,	
       set: int -> unit,
       reset: unit -> unit,
       getMin: unit -> int,
       getMax: unit -> int}
  type elapsedTimeCounter =
      {name: string,
       toString: counterSetOrder -> string -> string,
       start: unit -> unit,
       stop: unit -> unit,
       reset: unit -> unit,
       getTime: unit -> Time.time}
  datatype counterSetInternal =
      CounterSetInternal of
      {name: string,
       addAccumulation: string -> accumulationCounter,
       addMinMax: string -> minMaxCounter,
       addElapsedTime: string -> elapsedTimeCounter,
       addSet: string -> counterSetInternal,
       listCounters: counterSetOrder -> counterInternal list,
       find: string -> counterInternal option,
       reset: unit -> unit}
  and counterInternal =
      AccumulationCounter of accumulationCounter
    | MinMaxCounter of minMaxCounter
    | ElapsedTimeCounter of elapsedTimeCounter
    | CounterSet of counterSetInternal
  type counterSet = 
      {name : string,
       addAccumulation : string -> accumulationCounter,
       addMinMax : string -> minMaxCounter,
       addElapsedTime : string -> elapsedTimeCounter,
       addSet : string -> counterSetInternal,
       listCounters : counterSetOrder -> counterInternal list,
       find : string -> counterInternal option,
       reset : unit -> unit}
  type counter =
      {counterInternal : counterInternal,
       toString : counterSetOrder -> string -> string,
       reset : unit -> unit}
  val dump : unit -> string
  val reset : unit -> unit
  val root : counterSet

  val TopCounterSet : counterSet
  val ElapsedCounterSet : counterSet
  val parseTimeCounter : elapsedTimeCounter
  val loadFileTimeCounter : elapsedTimeCounter
  val generateMainTimeCounter : elapsedTimeCounter
  val elaborationTimeCounter : elapsedTimeCounter
  val nameEvaluationTimeCounter : elapsedTimeCounter
  val valRecOptimizationTimeCounter : elapsedTimeCounter
  val fundeclElaborationTimeCounter : elapsedTimeCounter
  val typeInferenceTimeCounter : elapsedTimeCounter
  val printerGenerationTimeCounter : elapsedTimeCounter
  val UncurryOptimizationTimeCounter : elapsedTimeCounter
  val polyTyEliminationCounter : elapsedTimeCounter
  val TypedCalcOptimizationTimeCounter : elapsedTimeCounter
  val RecordCalcOptimizationTimeCounter : elapsedTimeCounter
  val matchCompilationTimeCounter : elapsedTimeCounter
  val typedElaborationTimeCounter : elapsedTimeCounter
  val reifyTopEnvTimeCounter : elapsedTimeCounter
  val ffiCompilationTimeCounter : elapsedTimeCounter
  val recordCompilationTimeCounter : elapsedTimeCounter
  val datatypeCompilationTimeCounter : elapsedTimeCounter
  val staticAnalysisTimeCounter : elapsedTimeCounter
  val recordUnboxingTimeCounter : elapsedTimeCounter
  val bitmapCompilationTimeCounter : elapsedTimeCounter
  val bitmapANormalizationTimeCounter : elapsedTimeCounter
  val bitmapANormalReorderTimeCounter : elapsedTimeCounter
  val typeCheckBitmapANormalTimeCounter : elapsedTimeCounter
  val closureConversionTimeCounter : elapsedTimeCounter
  val callingConventionCompileTimeCounter : elapsedTimeCounter
  val anormalizeTimeCounter : elapsedTimeCounter
  val machineCodeGenTimeCounter : elapsedTimeCounter
  val insertCheckGCTimeCounter : elapsedTimeCounter
  val stackAllocationTimeCounter : elapsedTimeCounter
  val llvmGenTimeCounter : elapsedTimeCounter
  val llvmEmitTimeCounter : elapsedTimeCounter
  val llvmOutputTimeCounter : elapsedTimeCounter
  val toYAANormalTimeCounter : elapsedTimeCounter
  val anormalOptimizationTimeCounter : elapsedTimeCounter
  val staticAllocationTimeCounter : elapsedTimeCounter
  val aigenerationTimeCounter : elapsedTimeCounter
  val rtlselectTimeCounter : elapsedTimeCounter
  val rtlTypecheckTimeCounter : elapsedTimeCounter
  val rtlstabilizeTimeCounter : elapsedTimeCounter
  val rtlrenameTimeCounter : elapsedTimeCounter
  val rtlcoloringTimeCounter : elapsedTimeCounter
  val rtlframeTimeCounter : elapsedTimeCounter
  val rtlemitTimeCounter : elapsedTimeCounter
  val rtlasmgenTimeCounter : elapsedTimeCounter
  val rtlasmprintTimeCounter : elapsedTimeCounter
  val assembleTimeCounter : elapsedTimeCounter
  val compilationTimeCounter : elapsedTimeCounter
  val parseArgsTimeCounter : elapsedTimeCounter
  val compileArgsTimeCounter : elapsedTimeCounter
  val printHelpTimeCounter : elapsedTimeCounter
  val loadInterfaceTimeCounter : elapsedTimeCounter
  val compileFileTimeCounter : elapsedTimeCounter
  val loadSMITimeCounter : elapsedTimeCounter
  val linkTimeCounter : elapsedTimeCounter
  val generateDependTimeCounter : elapsedTimeCounter

end
